package com.blast.cn.adapter

import com.blast.cn.R
import com.blast.cn.bean.SettingsItem
import com.chad.library.adapter.base.BaseViewHolder
import com.wxl.common.adapter.AbsKeyEventAdapter
import com.wxl.common.util.ImgLoader

class SettingsAdapter : AbsKeyEventAdapter<SettingsItem> {

    constructor(data: List<SettingsItem>) : super(R.layout.item_settings_layout, data)

    override fun convert(helper: BaseViewHolder, item: SettingsItem) {
        super.convert(helper, item)
        if (helper.adapterPosition == 0) {
            helper.setGone(R.id.settingsItemOneLayout, true)
            helper.setGone(R.id.settingsItemOtherLayout, false)
            ImgLoader.loadResouce(helper.getView(R.id.settingsItemOneImg), item.res)
            helper.setText(R.id.settingsItemLoginName,item.text)
            helper.addOnClickListener(
                R.id.settingsItemSwitchLogin,
                R.id.settingsItemUpdatePwd,
                R.id.settingsItemUploadCjqData
            )
        } else {
            helper.setGone(R.id.settingsItemOneLayout, false)
            helper.setGone(R.id.settingsItemOtherLayout, true)
            ImgLoader.loadResouce(helper.getView(R.id.settingsItemOtherImg), item.res)

            helper.setText(R.id.settingsItemOtherText, item.text)
        }
        if(helper.adapterPosition == 1){
            helper.setGone(R.id.settingsItemMoreText,false)
            helper.setGone(R.id.settingsItemLoginSurplusText,true)
            helper.setText(R.id.settingsItemLoginSurplusText,item.timeSurplus)
        } else {
            helper.setGone(R.id.settingsItemMoreText,true)
            helper.setGone(R.id.settingsItemLoginSurplusText,false)
        }
    }

    override fun convertPayloads(
        helper: BaseViewHolder,
        item: SettingsItem,
        payloads: MutableList<Any>
    ) {
        if(payloads.isNotEmpty() && helper.adapterPosition == 1){
            helper.setGone(R.id.settingsItemMoreText,false)
            helper.setGone(R.id.settingsItemLoginSurplusText,true)
            helper.setText(R.id.settingsItemLoginSurplusText,item.timeSurplus)
        }
    }
}